package com.example.employ.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.employ.dao.entity.CompaniesDO;
import com.example.employ.dao.mapper.CompaniesMapper;
import com.example.employ.dto.response.CompaniesListRespDTO;
import com.example.employ.service.CompaniesService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class CompaniesServiceImpl extends ServiceImpl<CompaniesMapper, CompaniesDO> implements CompaniesService {
    /**
     * 获取公司列表
     * @return 公司名字，公司简介
     */
    @Override
    public List<CompaniesListRespDTO> companiesList() {
        // 直接全查，除了删除了的
        LambdaQueryWrapper<CompaniesDO> queryWrapper = Wrappers.lambdaQuery(CompaniesDO.class)
                .eq(CompaniesDO::getDelFlag, 0);
        List<CompaniesDO> companiesDOS = baseMapper.selectList(queryWrapper);
        List<CompaniesListRespDTO> result = new ArrayList<>();
        for (CompaniesDO companiesDO : companiesDOS) {
            CompaniesListRespDTO companiesListRespDTO = new CompaniesListRespDTO();
            // 公司简介
            companiesListRespDTO.setDescription(companiesDO.getDescription());
            // 公司 ID
            companiesListRespDTO.setId(companiesDO.getId());
            // 公司名字
            companiesListRespDTO.setName(companiesDO.getName());
            result.add(companiesListRespDTO);
        }
        return result;
    }
}
